const { mock } = require("mockjs")
const { lodash } = require('lodash');

const totalCount = 3
const List = [
  {
    id: 1,
    name: '2021年春节促销买十赠一',
    status: 0,
    categories: [
      {
        name: '水饺',
        products: [
          {
            material: '三鲜水饺',
            regular: '300克/盒',
            price: 18
          },
          {
            material: '香菇鲜肉水饺',
            regular: '500克/盒',
            price: 22
          },
          {
            material: '茴香鲜肉水饺',
            regular: '300克/盒',
            price: 19
          },
          {
            material: '韭菜鸡蛋水饺',
            regular: '300克/盒',
            price: 12
          }
        ]
      },
      {
        name: '馄饨',
        products: [
          {
            material: '早餐小馄饨',
            regular: '300克/袋',
            price: 12
          },
          {
            material: '东北大馄饨',
            regular: '500克/袋',
            price: 20
          },
          {
            material: '三鲜大馄饨',
            regular: '300克/袋',
            price: 22
          }
        ]
      },
      {
        name: '面条',
        products: [
          {
            material: '私房牛肉面',
            regular: '600克/盒',
            price: 22
          }
        ]
      }
    ],
    createdUser: '张三',
    created: '@datetime',
  },
  {
    id: 2,
    name: '新加盟客户优惠政策',
    status: 1,
    categories: [
      {
        name: '包子',
        products: [
          {
            material: '三鲜包子',
            regular: '300克/盒',
            price: 18
          },
          {
            material: '香菇鲜肉包子',
            regular: '500克/盒',
            price: 22
          },
          {
            material: '圆葱猪肉包子',
            regular: '300克/盒',
            price: 19
          }
        ]
      },
      {
        name: '馄饨',
        products: [
          {
            material: '早餐小馄饨',
            regular: '300克/袋',
            price: 19
          },
          {
            material: '东北大馄饨',
            regular: '500克/袋',
            price: 22
          },
          {
            material: '三鲜大馄饨',
            regular: '300克/袋',
            price: 18
          }
        ]
      },
      {
        name: '面条',
        products: [
          {
            material: '私房牛肉面',
            regular: '600克/盒',
            price: 22
          },
          {
            material: '兰州牛肉面拉面',
            regular: '400克/盒',
            price: 21
          }
        ]
      }
    ],
    createdUser: '李四',
    created: '@datetime',
  }
]

module.exports = [
  {
    url: '/priceStrategyManagement/getList',
    type: 'post',
    response(config) {
      const { name = '', pageNo = 1, pageSize = 20 } = config.body
      let mockList = List.filter((item) => {
        if (name && item.name.indexOf(name) < 0) return false
        return true
      })
      const pageList = mockList.filter(
        (item, index) =>
          index < pageSize * pageNo && index >= pageSize * (pageNo - 1)
      )
      return {
        code: 200,
        msg: 'success',
        totalCount,
        data: pageList,
      }
    },
  },
  {
    url: '/priceStrategyManagement/doEdit',
    type: 'post',
    response() {
      return {
        code: 200,
        msg: '模拟保存成功',
      }
    },
  },
  {
    url: '/priceStrategyManagement/doDelete',
    type: 'post',
    response() {
      return {
        code: 200,
        msg: '模拟删除成功',
      }
    },
  },
  {
    url: '/priceStrategyManagement/getInfo',
    type: 'post',
    response(config) {
      const { name } = config.body
      return {
        code: 200,
        msg: 'success',
        data: List.find((item) => { return item.name == name })
      }
    },
  }
]
